import 'package:flutter/material.dart';
import 'package:islandingclub/constants/hero_constants.dart';
import 'package:islandingclub/constants/image_constants.dart';
import 'package:islandingclub/screens/explore_screen.dart';
import 'package:islandingclub/screens/home_screen.dart';
import 'package:islandingclub/screens/me_screen.dart';
import 'package:islandingclub/utils/extensions.dart';

class MainScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  final List<Widget> _screens = [HomeScreen(), ExploreScreen(), MeScreen()];
  int _currentIndex = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Transform.scale(
          scale: 30.0,
          child: Hero(
            tag: HeroConstants.SPLASH_LOGO,
            child: Image.asset(
              ImageConstants.logo,
            ),
          ),
        ),
        // Column(
        //   children: [
        //     Expanded(
        //       child: Container(
        //         child: _screens[_currentIndex],
        //       ),
        //     ),
        //     _buildBottomNavigationBar()
        //   ],
        // )
        Scaffold(
          backgroundColor: Colors.transparent,
          body: _screens[_currentIndex],
          bottomNavigationBar: _buildBottomNavigationBar(),
        ),
      ],
    );
  }

  Widget _buildBottomNavigationBar() {
    return Theme(
      data: ThemeData(),
      child: BottomNavigationBar(
        items: [
          _buildBottomNavigationBarItem(ImageConstants.ic_tab_unselect_home,
              ImageConstants.ic_tab_home, '首页'),
          _buildBottomNavigationBarItem(ImageConstants.ic_tab_unselect_explore,
              ImageConstants.ic_tab_explore, '探索'),
          _buildBottomNavigationBarItem(
              ImageConstants.ic_tab_unselect_me, ImageConstants.ic_tab_me, '我'),
        ],
        showUnselectedLabels: true,
        backgroundColor: Color(0x0f000000),
        elevation: 0,
        selectedItemColor: Colors.black54,
        unselectedItemColor: Colors.black12,
        unselectedFontSize: 12.sp,
        selectedFontSize: 12.sp,
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }

  BottomNavigationBarItem _buildBottomNavigationBarItem(
      String icon, String activeIcon, String label) {
    return BottomNavigationBarItem(
      icon: Image.asset(
        icon,
        width: 18.w,
        height: 18.w,
      ),
      activeIcon: Image.asset(
        activeIcon,
        width: 18.w,
        height: 18.w,
      ),
      label: label,
    );
  }
}
